package net.lab1024.sa.gateway.processor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

@Slf4j
@Component
public class ProcessorFactory {
    private static final ConcurrentMap<String, IProcessor> PROCESSORS = new ConcurrentHashMap<>();

    public ProcessorFactory(IProcessor... processors) {
        Arrays.asList(processors).forEach(p -> {
            String className = p.getClass().getName();
            PROCESSORS.put(className, p);
            log.info("Initialized processor: {}", className);
        });
    }

    public static IProcessor get(String className) {
        return PROCESSORS.get(className);
    }
}